package org.exam.system.controller;

import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.exam.blog.domain.ArticleType;
import org.exam.system.domain.Menu;
import org.exam.system.query.MenuQuery;
import org.exam.system.service.IMenuService;
import org.exam.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/menu")
@Api(tags = "用户提示")
public class MenuController {
    @ApiOperation(value = "查询单个接口")
    @PutMapping
    public JsonResult add(@RequestBody Menu menu) {
        try {
            if (menu.getId() == null) {
                iMenuService.add(menu);

                return JsonResult.success();
            } else {
                iMenuService.update(menu);
                return JsonResult.success();
            }
        } catch (Exception e) {
            e.printStackTrace();
            return JsonResult.error();

        }
    }

    @Autowired
    private IMenuService iMenuService;

    @DeleteMapping("/{id}")
    public JsonResult delete(@PathVariable Long id) {
        try {
            iMenuService.delete(id);
            return JsonResult.success();
        } catch (Exception e) {
            e.printStackTrace();
            return JsonResult.error();
        }
    }

    @GetMapping("/{id}")
    public Menu get(@PathVariable("id") Long id) {
        return iMenuService.get(id);
    }

    @GetMapping
    public List<Menu> getAll() {
        return iMenuService.getAll();
    }

    @PatchMapping
    public JsonResult patchDelete(@RequestBody Long[] ids) {
        try {
            iMenuService.patchDelete(ids);
            return JsonResult.success();
        } catch (Exception e) {
            e.printStackTrace();
            return JsonResult.error();
        }
    }
    @GetMapping("/typeTree")
    public List<Menu> typeTree() {
        return iMenuService.typeTree();


    }

    @PostMapping
    public PageInfo<Menu> queryPage(@RequestBody MenuQuery menuQuery) {
        return iMenuService.queryPage(menuQuery);
    }




}
